package org.x.user.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import java.lang.String;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.x.common.base.result.Result;
import org.x.user.entity.SysUsers;
import org.x.user.entity.SysUserDept;
import org.x.user.entity.SysUserRoles;
import org.x.user.entity.SysTokens;
import org.x.user.dto.CreateGroup;
import org.x.user.dto.DeleteGroup;
import org.x.user.dto.UpdateGroup;
import org.x.user.dto.UserDTO;
import org.x.user.query.QueryGroup;
import org.x.user.service.UserService;
import org.x.user.vo.UserVO;

/**
 * 用户管理
 *
 * @author 夏包包
 * @date 2025-03-08 13:39:03
 */
@Tag(name = "用户管理")
@RequestMapping("user")
@RestController
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 获取用户列表
     */
    @GetMapping("/list")
    public Result<?> getUserList() {
        List<SysUsers> userList = userService.list();
        return Result.success(userList);
    }

    /**
     * add
     *
     * @param userDTO 用户信息入参实体类
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @Operation(summary = "add")
    @ResponseBody
    public Result<Boolean> addUser(@RequestBody @Validated(CreateGroup.class) UserDTO userDTO) {
        Boolean result = userService.addUser(userDTO);
        return Result.success(result);
    }

    /**
     * delete
     *
     * @param userId 用户信息入参实体类
     * @return
     */
    @RequestMapping(value = "/delete/{userId}", method = RequestMethod.DELETE)
    @Operation(summary = "delete")
    @ResponseBody
    public Result<Boolean> deleteUser(@PathVariable String userId) {
        Boolean result = userService.removeById(userId);
        return Result.success(result);
    }

    /**
     * update
     *
     * @param userDTO 用户信息入参实体类
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @Operation(summary = "update")
    @ResponseBody
    public Result<Boolean> updateUser(@RequestBody @Validated(UpdateGroup.class) UserDTO userDTO) {
        Boolean result = userService.updateUser(userDTO);
        return Result.success(result);
    }

    /**
     * info
     *
     * @param userId
     * @return
     */
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @Operation(summary = "info")
    public Result<UserVO> userInfo(@Validated(QueryGroup.class) String userId) {
        UserVO result = userService.userInfo(userId);
        return Result.success(result);
    }

    /**
     * dept
     *
     * @param userId
     * @return
     */
    @RequestMapping(value = "/dept", method = RequestMethod.GET)
    @Operation(summary = "dept")
    public Result<List<SysUserDept>> userDept(@Validated(QueryGroup.class) String userId) {
        List<SysUserDept> result = userService.userDept(userId);
        return Result.success(result);
    }

    /**
     * roles
     *
     * @param userId
     * @return
     */
    @RequestMapping(value = "/roles", method = RequestMethod.GET)
    @Operation(summary = "roles")
    public Result<List<SysUserRoles>> userRoles(@Validated(QueryGroup.class) String userId) {
        List<SysUserRoles> result = userService.userRoles(userId);
        return Result.success(result);
    }

    /**
     * tokens
     *
     * @param userId
     * @return
     */
    @RequestMapping(value = "/tokens", method = RequestMethod.GET)
    @Operation(summary = "tokens")
    public Result<List<SysTokens>> userTokens(@Validated(QueryGroup.class) String userId) {
        List<SysTokens> result = userService.userTokens(userId);
        return Result.success(result);
    }


}
